#ifndef SIDEBARWINDOW_H
#define SIDEBARWINDOW_H

#include <vector>
#include <iostream>
#include <QtCore/qlogging.h>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QLayout>
#include <QtWidgets/QFrame>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QAction>
#include <QtWidgets/QSizePolicy>
#include <QtWidgets/QMenu>

#include "Config.h"
#include "NoteBookButton.h"
#include "NoteBookDirButton.h"
#include "SearchButton.h"
#include "NavigationWindows.h"

namespace hps {

// 侧边栏
class SideBarWindow: public QWidget {
Q_OBJECT
public:
    SideBarWindow(QWidget *parent, QHBoxLayout *layout);
    SideBarWindow() = default;
    // 初始化组件
    void init();

    // 配置UI
    void setSideBarUi();

    // 相应函数
    void rspFunc();
    NoteBookButton *getNoteBookButton() const { return m_noteBookButton; };
    NoteBookDirButton *getNoteDirButton() const { return m_noteBookDirButton; }
    SearchButton *getSearchButton() const { return m_searchButton; }
    QAction* getHideButtonAction() const {return m_hideButtonAction; }
    ButtonName::Button getRightClickedButtonName();
    void setRightClickedButtonName(ButtonName::Button name);
    // 获取当前打开导航栏的Button名字
    ButtonName::Button getNowOpenButtonName();
    // 设置当前打开导航栏Button的名字
    void setNowOpenButtonName(ButtonName::Button name);
    // 点击之后的颜色：设计局部样式表
    void setClickedColor(QPushButton *button);
    // 恢复颜色：将局部样式表设空
    void restoreColor(QPushButton *button);
    // 将全部按钮的样式表清空
    void restoreAllColor();
    // 移除工具栏中的按钮
    void removeButton(QWidget *widget, ButtonName::Button name);
    // 展示菜单
    void showRightClickMenu(QPushButton *pushButton, ButtonName::Button name);
public slots:

    // 点击“更多"的时候
    void clickedMore();
    // 点击更多工具窗口中的笔记本action
    void clickedNoteBookAction();
    // 点击更多工具窗口中的笔记本目录action
    void clickedNoteBookDirAction();
    // 点击更多工具窗口中的搜索action
    void clickedSearchAction();
    // 展示NoteBook的右键菜单
    void noteBookRightClicked();
    // 展示NoteBookDir的右键菜单
    void noteBookDirRightClicked();
    // 展示搜索的右键菜单
    void searchRightClicked();
    // 移动到顶端
    void moveButtonToTop();
    // 移动到底部
    void moveButtonToBottom();
private:
    // this相关
    QHBoxLayout *m_parentLayout;
    QVBoxLayout *m_sideBarlayout;   // 侧边栏的布局管理器

    // 侧边工具栏相关
    QPushButton *m_more;
    QIcon *m_moreIcon;
    QMenu m_moreMenu;
    QAction *m_NoteBookAction;
    QAction *m_dirAction;
    QAction *m_searchAction;
    NoteBookButton *m_noteBookButton;
    NoteBookDirButton *m_noteBookDirButton;
    SearchButton *m_searchButton;

    std::vector<QPushButton *> m_buttonList;

    ButtonName::Button m_openButtonName = ButtonName::unknow; // 正在打开的侧边导航栏
    ButtonName::Button m_rightClickedButtonName = ButtonName::unknow; // 右键点击的工具按钮名
    QMenu m_rightClickButtonMenu;
    // 隐藏button
    QAction *m_hideButtonAction;
    // 移动button的菜单
    QMenu *m_moveMenu;
    QAction *m_moveTop;
    QAction *m_moveBottom;
};

}

#endif